package com.uniflow.entity;

import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 表单数据实体类
 */
@ApiModel(description = "表单数据")
@TableName("form_data")
public class FormData {
    
    @ApiModelProperty("数据ID")
    @TableId(type = IdType.ASSIGN_UUID)
    private String id;
    
    @ApiModelProperty("表单ID")
    @TableField("form_id")
    private String formId;
    
    @ApiModelProperty("表单名称")
    @TableField("form_name")
    private String formName;
    
    @ApiModelProperty("表单版本")
    @TableField("form_version")
    private Integer formVersion;
    
    @ApiModelProperty("业务键")
    @TableField("business_key")
    private String businessKey;
    
    @ApiModelProperty("流程实例ID")
    @TableField("process_instance_id")
    private String processInstanceId;
    
    @ApiModelProperty("任务ID")
    @TableField("task_id")
    private String taskId;
    
    @ApiModelProperty("表单数据JSON")
    @TableField("data_json")
    private String dataJson;
    
    @ApiModelProperty("数据状态")
    @TableField("status")
    private String status;
    
    @ApiModelProperty("提交人ID")
    @TableField("submitted_by")
    private String submittedBy;
    
    @ApiModelProperty("提交人姓名")
    @TableField("submitted_by_name")
    private String submittedByName;
    
    @ApiModelProperty("提交时间")
    @TableField("submitted_at")
    private LocalDateTime submittedAt;
    
    @ApiModelProperty("审核人ID")
    @TableField("reviewed_by")
    private String reviewedBy;
    
    @ApiModelProperty("审核人姓名")
    @TableField("reviewed_by_name")
    private String reviewedByName;
    
    @ApiModelProperty("审核时间")
    @TableField("reviewed_at")
    private LocalDateTime reviewedAt;
    
    @ApiModelProperty("审核意见")
    @TableField("review_comment")
    private String reviewComment;
    
    @ApiModelProperty("备注")
    @TableField("remark")
    private String remark;
    
    @ApiModelProperty("创建时间")
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @ApiModelProperty("更新时间")
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;
    
    // 扩展字段（不存储到数据库）
    
    @ApiModelProperty("表单数据Map")
    @TableField(exist = false)
    private Map<String, Object> data;
    
    @ApiModelProperty("表单信息")
    @TableField(exist = false)
    private Form form;
    
    @ApiModelProperty("流程信息")
    @TableField(exist = false)
    private ProcessInstance processInstance;
    
    @ApiModelProperty("任务信息")
    @TableField(exist = false)
    private Task task;
    
    // Getters and Setters
    
    public String getId() {
        return id;
    }
    
    public void setId(String id) {
        this.id = id;
    }
    
    public String getFormId() {
        return formId;
    }
    
    public void setFormId(String formId) {
        this.formId = formId;
    }
    
    public String getFormName() {
        return formName;
    }
    
    public void setFormName(String formName) {
        this.formName = formName;
    }
    
    public Integer getFormVersion() {
        return formVersion;
    }
    
    public void setFormVersion(Integer formVersion) {
        this.formVersion = formVersion;
    }
    
    public String getBusinessKey() {
        return businessKey;
    }
    
    public void setBusinessKey(String businessKey) {
        this.businessKey = businessKey;
    }
    
    public String getProcessInstanceId() {
        return processInstanceId;
    }
    
    public void setProcessInstanceId(String processInstanceId) {
        this.processInstanceId = processInstanceId;
    }
    
    public String getTaskId() {
        return taskId;
    }
    
    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }
    
    public String getDataJson() {
        return dataJson;
    }
    
    public void setDataJson(String dataJson) {
        this.dataJson = dataJson;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public String getSubmittedBy() {
        return submittedBy;
    }
    
    public void setSubmittedBy(String submittedBy) {
        this.submittedBy = submittedBy;
    }
    
    public String getSubmittedByName() {
        return submittedByName;
    }
    
    public void setSubmittedByName(String submittedByName) {
        this.submittedByName = submittedByName;
    }
    
    public LocalDateTime getSubmittedAt() {
        return submittedAt;
    }
    
    public void setSubmittedAt(LocalDateTime submittedAt) {
        this.submittedAt = submittedAt;
    }
    
    public String getReviewedBy() {
        return reviewedBy;
    }
    
    public void setReviewedBy(String reviewedBy) {
        this.reviewedBy = reviewedBy;
    }
    
    public String getReviewedByName() {
        return reviewedByName;
    }
    
    public void setReviewedByName(String reviewedByName) {
        this.reviewedByName = reviewedByName;
    }
    
    public LocalDateTime getReviewedAt() {
        return reviewedAt;
    }
    
    public void setReviewedAt(LocalDateTime reviewedAt) {
        this.reviewedAt = reviewedAt;
    }
    
    public String getReviewComment() {
        return reviewComment;
    }
    
    public void setReviewComment(String reviewComment) {
        this.reviewComment = reviewComment;
    }
    
    public String getRemark() {
        return remark;
    }
    
    public void setRemark(String remark) {
        this.remark = remark;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
    
    public Map<String, Object> getData() {
        return data;
    }
    
    public void setData(Map<String, Object> data) {
        this.data = data;
    }
    
    public Form getForm() {
        return form;
    }
    
    public void setForm(Form form) {
        this.form = form;
    }
    
    public ProcessInstance getProcessInstance() {
        return processInstance;
    }
    
    public void setProcessInstance(ProcessInstance processInstance) {
        this.processInstance = processInstance;
    }
    
    public Task getTask() {
        return task;
    }
    
    public void setTask(Task task) {
        this.task = task;
    }
    
    /**
     * 判断是否为草稿状态
     */
    public boolean isDraft() {
        return "draft".equals(this.status);
    }
    
    /**
     * 判断是否已提交
     */
    public boolean isSubmitted() {
        return "submitted".equals(this.status);
    }
    
    /**
     * 判断是否已审核
     */
    public boolean isReviewed() {
        return "approved".equals(this.status) || "rejected".equals(this.status);
    }
    
    /**
     * 判断是否已通过
     */
    public boolean isApproved() {
        return "approved".equals(this.status);
    }
    
    /**
     * 判断是否已拒绝
     */
    public boolean isRejected() {
        return "rejected".equals(this.status);
    }
    
    /**
     * 获取状态描述
     */
    public String getStatusDescription() {
        switch (this.status) {
            case "draft":
                return "草稿";
            case "submitted":
                return "已提交";
            case "approved":
                return "已通过";
            case "rejected":
                return "已拒绝";
            case "processing":
                return "处理中";
            case "completed":
                return "已完成";
            default:
                return "未知";
        }
    }
}